/**
 * Project Name:emm-estate
 * File Name:ActNodeDataServiceFacade.java
 * Package Name:com.emm.yixun.estate.service.impl
 * Date:2017年9月6日上午10:58:07
 *
 */
package com.emm.yixun.estate.service.impl;

import javax.jws.WebService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emm.yixun.basic.service.ActNodeDataService;
import com.emm.yixun.common.model.User;
import com.emm.yixun.common.model.dto.ActNodeDataDto;
import com.emm.yixun.common.model.dto.ActNodeQuery;
import com.emm.yixun.common.model.enums.ActDataTypeEnum;
import com.emm.yixun.common.page.Page;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.estate.service.ActNodeDataServiceFacade;

/**
 * ClassName:ActNodeDataServiceFacade <br/>
 * Function: 流程数据接口 <br/>
 * Date: 2017年9月6日 上午10:58:07 <br/>
 * 
 * @author Administrator
 * @version
 * @since JDK 1.6
 * @see
 */
@Service("actNodeDataServiceFacade")
@WebService(name = "com.emm.yixun.estate.service.ActNodeDataServiceFacade")
public class ActNodeDataServiceFacadeImpl implements ActNodeDataServiceFacade {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ActNodeDataService actNodeDataService;
	
	@Override
	public Page<ActNodeDataDto> queryActHaveList(ActNodeQuery actNodeQuery,User user, int beginNum, int endNum) {
		Page<ActNodeDataDto> responseList = new Page<ActNodeDataDto>();
		try {
			actNodeQuery = createTypeSql(actNodeQuery, user);
			responseList = actNodeDataService.queryActHaveList(actNodeQuery,beginNum, endNum);
			responseList.setSuccess(true);
		} catch (Exception e) {
			responseList.setSuccess(false);
			logger.error("queryActHaveList error: ", e);
		}
		return responseList;
	}

	/**
	 * 
	 * createTypeSql:(根据不同的类型查询生成不同的). <br/>
	 * 
	 * @author Administrator
	 * @param actNodeQuery
	 * @return
	 * @since JDK 1.6
	 */
	public ActNodeQuery createTypeSql(ActNodeQuery actNodeQuery, User user) {
		actNodeQuery.setMerchantId(user.getMerchantId());
		if (actNodeQuery.getqType().equals(ActDataTypeEnum.ACT_1.getNo())) {
			actNodeQuery.setQueryTypeSql(" and t.END_TIME_ IS NULL ");
			actNodeQuery.setUserId(user.getId());
		} else if (actNodeQuery.getqType().equals(ActDataTypeEnum.ACT_2.getNo())) {
			actNodeQuery.setQueryTypeSql(" and t.END_TIME_ IS NOT NULL ");
			actNodeQuery.setUserId(user.getId());
		} else if (actNodeQuery.getqType().equals(ActDataTypeEnum.ACT_3.getNo())) {
			actNodeQuery.setStartUserName(user.getUserName());
		}
		return actNodeQuery;
	}

	@Override
	public ResponseList<ActNodeDataDto> queryActByRoomId(ActNodeQuery actNodeQuery) {
		ResponseList<ActNodeDataDto> responseList = new ResponseList<ActNodeDataDto>();
		try {
			actNodeQuery.setQueryTypeSql(" and t.END_TIME_ IS NULL ");
			responseList.setEntity(actNodeDataService.queryActByBusinessKey(actNodeQuery, 0, 10));
			responseList.setSuccess(true);
			return responseList;
		} catch (Exception e) {
			responseList.setSuccess(false);
			logger.error("error",e);
		}
		return responseList;
	}
}
